package com.ruoyi.project.business.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.business.domain.*;
import com.ruoyi.project.business.service.IBusinessAreaService;
import com.ruoyi.project.business.service.IBusinessNoticeService;
import com.ruoyi.project.business.service.ITgxsNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.service.IBusinessAreaOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 租地订单Controller
 * 
 * @author ruoyi
 * @date 2020-10-19
 */
@RestController
@RequestMapping("/business/areaOrder")
public class BusinessAreaOrderController extends BaseController
{
    @Autowired
    private IBusinessAreaOrderService businessAreaOrderService;
    @Autowired
    private IBusinessAreaService businessAreaService;
    @Autowired

    private IBusinessNoticeService businessNoticeService;

    @Autowired

    private ITgxsNoticeService tgxsNoticeService;

    /**
     * 查询租地订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessAreaOrder businessAreaOrder)
    {
        startPage();
        List<BusinessAreaOrder> list = businessAreaOrderService.selectBusinessAreaOrderList(businessAreaOrder);
        return getDataTable(list);
    }

    /**
     * 导出租地订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:export')")
    @Log(title = "租地订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessAreaOrder businessAreaOrder)
    {
        List<BusinessAreaOrder> list = businessAreaOrderService.selectBusinessAreaOrderList(businessAreaOrder);
        ExcelUtil<BusinessAreaOrder> util = new ExcelUtil<BusinessAreaOrder>(BusinessAreaOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取租地订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessAreaOrderService.selectBusinessAreaOrderById(id));
    }

    /**
     * 新增租地订单
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:add')")
    @Log(title = "租地订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessAreaOrder businessAreaOrder)
    {
        return toAjax(businessAreaOrderService.insertBusinessAreaOrder(businessAreaOrder));
    }

    /**
     * 修改租地订单
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:edit')")
    @Log(title = "租地订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessAreaOrder businessAreaOrder)
    {
        return toAjax(businessAreaOrderService.updateBusinessAreaOrder(businessAreaOrder));
    }

    /**
     * 删除租地订单
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:remove')")
    @Log(title = "租地订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessAreaOrderService.deleteBusinessAreaOrderByIds(ids));
    }


    /**
     * 查询租地订单列表(支付过的订单列表)
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:areaList')")
    @GetMapping("/areaList")
    public TableDataInfo areaList(BusinessAreaOrder businessAreaOrder)
    {
        startPage();
        List<BusinessArea> list = businessAreaOrderService.areaList(businessAreaOrder);
        return getDataTable(list);
    }

    /**
     * 添加农田反馈(添加消息)
     */
    @PreAuthorize("@ss.hasPermi('business:areaOrder:addadvice')")
    @Log(title = "租地土地", businessType = BusinessType.UPDATE)
    @PutMapping("/addadvice")
    public AjaxResult addadvice(@RequestBody BusinessArea businessArea)
    {
        BusinessArea businessArea1=businessAreaService.selectBusinessAreaById(businessArea.getId());
        TgxsNotice  tgxsNotice=new TgxsNotice();
        tgxsNotice.setTitle("土地消息");
        tgxsNotice.setMessage(businessArea.getPlantAdvice());
        tgxsNotice.setType(2);
        tgxsNotice.setReceiverId(businessArea1.getUserId());
        tgxsNotice.setState(0);
        tgxsNotice.setIsDelete(0);
        tgxsNoticeService.insertTgxsNotice(tgxsNotice);

//        BusinessNotice businessNotice=new BusinessNotice();
//        businessNotice.setNoticeTitle("土地消息");
//        businessNotice.setNoticeContent(businessArea.getPlantAdvice());
//        businessNotice.setNoticeType("3");
//        businessNotice.setUserId(businessArea1.getUserId());
//        businessNoticeService.insertBusinessNotice(businessNotice);
        return toAjax(businessAreaService.updateBusinessArea(businessArea));
    }

}
